<!--
 * @Description: 
 * @Version: 1.0
 * @Author: tao
 * @Date: 2021-01-21 13:28:32
 * @LastEditors: tao
 * @LastEditTime: 2021-04-19 15:24:42
-->
<template>
  <Model
    :title="row.edit ? '编辑' : '添加'"
    :width="400"
    :show="show"
    @confirm="confirm"
    @cancel="cancel"
  >
    <Form slot="form">
      <FormItem label="账号">
        <a-input v-model="row.username" placeholder="请输入内容"></a-input>
      </FormItem>
      <FormItem v-if="!row.edit" label="密码">
        <a-input
          type="password"
          v-model="row.password"
          placeholder="请输入内容"
        ></a-input>
      </FormItem>
      <FormItem label="身份">
        <a-select
          show-search
          :default-value="row.type"
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 181.6px"
          @change="(value) => changeValue(value, 'type')"
        >
          <a-select-option
            v-for="item in Object.keys(admins)"
            :key="item"
            :value="item"
          >
            {{ admins[item] }}
          </a-select-option>
        </a-select>
      </FormItem>
    </Form>
  </Model>
</template>

<script>
import Model from "components/common/model/Model";
import Form from "components/common/form/Form";
import FormItem from "components/common/form/formItem/FormItem";
import FormDoubleItem from "components/common/form/formDoubleItem/FormDoubleItem";
import { admins } from "assets/data/other";
export default {
  components: {
    Model,
    Form,
    FormItem,
  },
  props: {
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    show: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {
      admins,
    };
  },
  methods: {
    changeValue(value, key) {
      this.row[key] = +value;
    },
    confirm() {
      const row = this.row;
      this.$emit("confirm", {
        ...row,
      });
    },
    cancel() {
      this.$emit("cancel");
    },
  },
};
</script>

<style lang="less" scoped>
.t-form {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-items: center;
  padding-right: 30px;
  .ant-btn {
    width: 150px !important;
  }
}
</style>